package com.zzptc.tkfate;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.zzptc.tkfate.Service.QichePinpaiServic;
import com.zzptc.tkfate.entity.QichePinpai;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getQichePinpaiInfo();
    }

    private void getQichePinpaiInfo() {
        //创建Retrofit对象
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://apis.juhe.cn/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        //创建接口对象
        QichePinpaiServic qichePinpaiServic = retrofit.create(QichePinpaiServic.class);
        //调用接口对象中定义的方法
        //Call<QichePinpai> call =qichePinpaiServic.getAllPinpai("79729168b7661c89f1f4e56936121f31","C");
        //调用Call接口中的异步方法
        Map<String,String> map=new HashMap<>();
        map.put("key","79729168b7661c89f1f4e56936121f31");
        map.put("first_letter","D");
        Call<QichePinpai> allPinpai = qichePinpaiServic.getAllPinpai(map);
        allPinpai.enqueue(new Callback<QichePinpai>() {
            @Override
            public void onResponse(Call<QichePinpai> call, Response<QichePinpai> response) {
                QichePinpai qichePinpai=response.body();
                Log.d(TAG, "onResponse: "+qichePinpai.getReason());
            }

            @Override
            public void onFailure(Call<QichePinpai> call, Throwable t) {
                Log.d(TAG, "onFailure: "+t.getMessage());

            }
        });
        /*call.enqueue(new Callback<QichePinpai>() {
            @Override
            public void onResponse(Call<QichePinpai> call, Response<QichePinpai> response) {
                QichePinpai qichePinpai=response.body();
                Log.d(TAG, "onResponse: "+qichePinpai.getResult().size());
            }

            @Override
            public void onFailure(Call<QichePinpai> call, Throwable t) {
                Log.d(TAG, "onFailure: "+t.getMessage());
            }
        });*/
    }
}
